package jp.ac.kobe_u.cs.cream;

import jp.ac.kobe_u.cs.cream.*;
import java.util.*;

public class Code implements Cloneable {
    public Condition conditions[];

    private Code() {
    }

    public Code(Network network) {
	List constraints = network.getConstraints();
	conditions = new Condition[constraints.size()];
	for (int i = 0; i < conditions.length; i++) {
	    Constraint c = network.getConstraint(i);
	    conditions[i] = c.extractCondition();
	}
    }

    public Object clone() {
	Code code = new Code();
	code.conditions = (Condition[])conditions.clone();
	return code;
    }

    public void setTo(Network network) {
	for (int i = 0; i < conditions.length; i++) {
	    if (conditions[i] == null) {
		network.getConstraint(i).clearCondition();
	    } else {
		conditions[i].setTo(network);
	    }
	}
    }

    public List operations() {
	List operations = new LinkedList();
	for (int i = 0; i < conditions.length; i++) {
	    if (conditions[i] != null) {
		operations.addAll(conditions[i].operations());
	    }
	}
	return operations;
    }

}
